package com.qkjia.day03;

import java.util.concurrent.*;

public class Test02_ThreadPool {
    public static void main(String[] args) {
        ExecutorService threadPool=new ThreadPoolExecutor(
                2,
                5,
                3L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy());
        //1.任务<=5 开启两个线程
        //2.任务<=8 开启<=5线程
        //3.任务>8  有可能开启拒绝策略
        for (int i = 0; i < 20; i++) {
            final int count = i;
            threadPool.execute(() -> {
                System.out.println(Thread.currentThread().getName() + "\t银行柜台为" + count + "位客户进行服务");
            });
        }
        threadPool.shutdown();
    }
}
